package com.cr.dataprotect.config;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * 完整性字段配置.对应xml文件.根标签为configuration.
 * <pre>
 *     <configuration>
 *         <
 *     </configuration>
 * </pre>
 *
 * @author ChenRui
 * @date 2022.10.23
 */
@Data
@ToString
@XStreamAlias("dataProtection")
public class DataProtectionConfig {
    @XStreamImplicit(itemFieldName = "clazz")
    private List<Clazz> clazzList;

    @Data
    @XStreamAlias("clazz")
    public static class Clazz {
        /**
         * clazz标签的属性，值为表对应的PO类全路径.
         */
        @XStreamAsAttribute
        private String type;
        @XStreamAsAttribute
        private String strategy;
        @XStreamAsAttribute
        private String encryptKeyAlias;
        @XStreamAsAttribute
        private String macKeyAlias;
        @XStreamImplicit(itemFieldName = "property")
        private List<Property> properties;
        @XStreamImplicit(itemFieldName = "extClzAttribute")
        private List<ExtClzAttribute> extClzAttributes;
    }

    @Data
    @XStreamAlias("property")
    public static class Property {
        /**
         * property标签的属性，值为表对应的PO字段名称.
         */
        @XStreamAsAttribute
        private String name;
        @XStreamImplicit(itemFieldName = "extProperty")
        private List<ExtProperty> extProperties;
    }

    @Data
    @XStreamAlias("extProperty")
    public static class ExtProperty {
        /**
         * property标签的扩展属性
         */
        @XStreamAsAttribute
        private String name;
        @XStreamAsAttribute
        private String value;
    }

    @Data
    @XStreamAlias("extClzAttributes")
    public static class ExtClzAttribute {
        /**
         * Clazz标签的扩展属性
         */
        @XStreamAsAttribute
        private String name;
        @XStreamAsAttribute
        private String value;
    }
}
